package com.roger.homecenterscreen.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.dp

/**
 * E-ink屏幕显示适配器
 * 专门为1200×1600 E-ink屏幕优化显示效果
 */
@Composable
fun EInkDisplayAdapter(
    content: @Composable () -> Unit
) {
    val configuration = LocalConfiguration.current
    val screenWidth = configuration.screenWidthDp.dp
    val screenHeight = configuration.screenHeightDp.dp
    
    // 计算E-ink屏幕的理想比例 (1200:1600 = 3:4)
    val targetRatio = 1200f / 1600f
    val currentRatio = screenWidth.value / screenHeight.value
    
    Box(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.White), // E-ink屏幕背景色
        contentAlignment = Alignment.Center
    ) {
        if (currentRatio > targetRatio) {
            // 屏幕太宽，需要在两边添加padding
            val targetWidth = screenHeight.value * targetRatio
            val horizontalPadding = ((screenWidth.value - targetWidth) / 2).dp
            
            Box(
                modifier = Modifier
                    .fillMaxHeight()
                    .width(targetWidth.dp)
                    .padding(horizontal = horizontalPadding)
            ) {
                content()
            }
        } else {
            // 屏幕太高，需要在上下添加padding
            val targetHeight = screenWidth.value / targetRatio
            val verticalPadding = ((screenHeight.value - targetHeight) / 2).dp
            
            Box(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(targetHeight.dp)
                    .padding(vertical = verticalPadding)
            ) {
                content()
            }
        }
    }
} 